function varargout = guiResult(varargin)
% GUIRESULT MATLAB code for guiResult.fig
%      GUIRESULT, by itself, creates a new GUIRESULT or raises the existing
%      singleton*.
%
%      H = GUIRESULT returns the handle to a new GUIRESULT or the handle to
%      the existing singleton*.
%
%      GUIRESULT('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUIRESULT.M with the given input arguments.
%
%      GUIRESULT('Property','Value',...) creates a new GUIRESULT or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before guiResult_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to guiResult_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help guiResult

% Last Modified by GUIDE v2.5 17-Jan-2014 07:24:27

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @guiResult_OpeningFcn, ...
                   'gui_OutputFcn',  @guiResult_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before guiResult is made visible.
function guiResult_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to guiResult (see VARARGIN)

% Choose default command line output for guiResult
handles.output = hObject;
global finalResult;
global finalNest;
global solutions;
global timeElapsed;
global optiIter;
B = sort(finalNest, 'descend');
c = size(B);
result = zeros(1,c(2));
test = ones(1, c(2));
for i=1:c(2)
    element = B(i);
    [row,column] = find(finalNest==element);
    sizeColumn = size(column);
    if sizeColumn(2) > 1
        if test(column(2)) == 1
            for k = 1:sizeColumn(2)
                if k > 1
                test(column(k)) = test(column(k-1)) + 1;
                end
            end
            a = column(1,1);
        else
            for k = 2:sizeColumn(2)
                if test(column(k)) > 0
                    a = column(1, test(column(k)));
                    test(column(k)) = 0;
                    break;
                end
            end
        end
    column = a;    
    end
    result(1,i) = column;
end
set(handles.result, 'String', mat2str(finalResult));
set(handles.edit2, 'String', mat2str(result));
set(handles.elTime, 'String', mat2str(round(timeElapsed)));
set(handles.optimum, 'String', mat2str(optiIter));

plot(handles.axes1,solutions(1,:),solutions(2,:));
title('Poprawa wartosci funkcji celu') % title
ylabel('Wartosc funkcji celu') % label for y axis
xlabel('Numer iteracji') 

% figure;
% plot(solutions(1,:),solutions(2,:));
% title('Poprawa wartosci funkcji celu') % title
% ylabel('Wartosc funkcji celu') % label for y axis
% xlabel('Numer iteracji');
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes guiResult wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = guiResult_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function result_Callback(hObject, eventdata, handles)
% hObject    handle to result (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of result as text
%        str2double(get(hObject,'String')) returns contents of result as a double


% --- Executes during object creation, after setting all properties.
function result_CreateFcn(hObject, eventdata, handles)
% hObject    handle to result (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global solutions;
figure;
%plot(solutions);
title('Poprawa wartości funkcji celu') % title
ylabel('Wartosc funkcji celu') % label for y axis
xlabel('Numer poprawy funkcji celu') 

% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over pushbutton1.
function pushbutton1_ButtonDownFcn(hObject, eventdata, handles)

% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



function elTime_Callback(hObject, eventdata, handles)
% hObject    handle to elTime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of elTime as text
%        str2double(get(hObject,'String')) returns contents of elTime as a double


% --- Executes during object creation, after setting all properties.
function elTime_CreateFcn(hObject, eventdata, handles)
% hObject    handle to elTime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function optimum_Callback(hObject, eventdata, handles)
% hObject    handle to optimum (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of optimum as text
%        str2double(get(hObject,'String')) returns contents of optimum as a double


% --- Executes during object creation, after setting all properties.
function optimum_CreateFcn(hObject, eventdata, handles)
% hObject    handle to optimum (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
